package tech.aistar.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import tech.aistar.pojo.PictureTable;
import tech.aistar.pojo.SongList;
import tech.aistar.pojo.entity.HotSongList;
import tech.aistar.service.Gedantu;
import tech.aistar.vo.Result;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


@RestController
@RequestMapping("gedan")
public class GedanController {
    @Autowired
    private Gedantu gedantu;

    @GetMapping("/fenye")
    public void setGedantu(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String pageNum = req.getParameter("pageNum");
        pageNum = pageNum == null?"1":pageNum;

        PageInfo<PictureTable> pageInfo = gedantu.findBypicture(Integer.valueOf(pageNum),2);

        out.print(JSON.toJSONString(new Result("200","分页成功",pageInfo)));
    }
    @GetMapping("/page")
    public void setGedantu1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String pageNum = req.getParameter("pageNum");
        pageNum = pageNum == null?"1":pageNum;

        PageInfo<HotSongList> pageInfo = gedantu.findBypicture1(Integer.valueOf(pageNum),2);

        out.print(JSON.toJSONString(new Result("200","分页成功",pageInfo)));
    }
    @GetMapping("/selet")
    public void setGedan(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();


            List<PictureTable> pictureTableList=gedantu.selectpicture();
            out.print(JSON.toJSONString(new Result("200","查询成功",pictureTableList)));
    }

    @GetMapping("/select")
    public void setGedan1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();


        List<HotSongList> pictureTableList=gedantu.selectpicture1();
        out.print(JSON.toJSONString(new Result("200","查询成功",pictureTableList)));
    }
    @PostMapping("pos")
    public void setGeda(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String id =  req.getParameter("id");
        System.out.println(id);
        if (null!=id)
        {
            List<PictureTable> pictureTableList=gedantu.selectbyid(Integer.valueOf(id));
            out.print(JSON.toJSONString(new Result("200","查询成功",pictureTableList)));
        }else
        {
            out.print(JSON.toJSONString(new Result("200","查询失败")));
        }
    }
    @PostMapping("pos1")
    public void setGeda1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        String id =  req.getParameter("id");
        System.out.println(id);
        if (null!=id)
        {
            List<HotSongList> pictureTableList=gedantu.selectbyid1(Integer.valueOf(id));
            out.print(JSON.toJSONString(new Result("200","查询成功",pictureTableList)));
        }else
        {
            out.print(JSON.toJSONString(new Result("200","查询失败")));
        }
    }

}
